using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Logging;
using System.Collections.ObjectModel;

namespace Jbe.TestSuite.LogViewer.Domain
{
    internal static class LogRecorder
    {
        private static ObservableCollection<LogEntry> logEntries;
        private static ReadOnlyObservableCollection<LogEntry> readOnlyLogEntries;
        private static bool enabled;


        static LogRecorder()
        {
            logEntries = new ObservableCollection<LogEntry>();
            readOnlyLogEntries = new ReadOnlyObservableCollection<LogEntry>(logEntries);
            enabled = true;
        }


        /// <summary>
        /// Collection of log entries.
        /// </summary>
        /// <remarks>It is not guaranteed that the collection changed events are thrown on the UI thread.</remarks>
        public static ReadOnlyObservableCollection<LogEntry> LogEntries
        {
            get { return readOnlyLogEntries; }
        }

        public static bool Enabled
        {
            get { return enabled; }
            set { enabled = value; }
        }


        public static void Log(LogEntry logEntry)
        {
            if (Enabled)
            {
                logEntries.Add(logEntry);
            }
        }

        public static void Log(object data)
        {
            if (Enabled)
            {
                LogEntry logEntry = new LogEntry();
                logEntry.Message = data.ToString();

                logEntries.Add(logEntry);
            }
        }

        public static void Clear()
        {
            logEntries.Clear();
        }
    }
}
